<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!-- 如果我们想上传文件  form中必须写  enctype属性  -->
    <form action="" enctype="multipart/form-data">
        <input type="file" >
    </form>
    <script>
        const xhr = new XMLHttpRequest(); // ajax对象

        xhr.open('post','http://localhost:8080/test/fourth');
        // xhr.setRequestHeader('content-type','application/x-www-form-urlencoded' )
        // xhr.send('name=lisi&age=23');

        // xhr.setRequestHeader('content-type','application/json' )
        // xhr.send('{"name":"zhangsan","age":19}');
        // 如果你想上传一个图片或者 视频 必须指定请求头  
        // xhr.setRequestHeader('content-type','multipart/form-data' )
        xhr.onload = function(){
            let res = JSON.parse(xhr.responseText);
            console.log(res.info.name);
            console.log(res.info.age);

        }
    </script>
</body>
</html>